package com.yike.user.service.impl;

import com.yike.user.entity.SysSetting;
import com.yike.user.mapper.SysSettingMapper;
import com.yike.user.service.SysSettingService;
import com.yike.user.param.SysSettingPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yike.common.base.BaseServiceImpl;
import com.yike.common.pagination.Paging;
import com.yike.common.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 系统属性配置表 服务实现类
 *
 * @author Sakura
 * @since 2024-09-29
 */
@Slf4j
@Service
public class SysSettingServiceImpl extends BaseServiceImpl<SysSettingMapper, SysSetting> implements SysSettingService {

    @Autowired
    private SysSettingMapper sysSettingMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSysSetting(SysSetting sysSetting) throws Exception {
        return super.save(sysSetting);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSysSetting(SysSetting sysSetting) throws Exception {
        return super.updateById(sysSetting);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSysSetting(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SysSetting> getSysSettingPageList(SysSettingPageParam sysSettingPageParam) throws Exception {
        Page<SysSetting> page = new PageInfo<>(sysSettingPageParam, OrderItem.desc(getLambdaColumn(SysSetting::getCreateTime)));
        LambdaQueryWrapper<SysSetting> wrapper = new LambdaQueryWrapper<>();
        IPage<SysSetting> iPage = sysSettingMapper.selectPage(page, wrapper);
        return new Paging<SysSetting>(iPage);
    }

}
